package com.chenyi.web.controller.system;

import java.util.List;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.http.ResponseEntity;
import org.springframework.http.HttpStatus;
import com.chenyi.common.annotation.Log;
import com.chenyi.common.core.controller.BaseController;
import com.chenyi.common.enums.BusinessType;
import com.chenyi.shop.domain.SysShopLogin;
import com.chenyi.shop.service.ISysShopLoginService;
import com.chenyi.common.utils.poi.ExcelUtil;
import com.chenyi.common.core.page.TableDataInfo;

/**
 * 商户登录记录Controller
 * 
 * @author chenyi
 * @date 2020-10-24
 */
@RestController
@RequestMapping("/admin/shop/login")
public class AdminShopLoginController extends BaseController
{
    @Autowired
    private ISysShopLoginService sysShopLoginService;

    /**
     * 查询商户登录记录列表
     */
    @PreAuthorize("@admin.hasPermi('shop:login:list')")
    @GetMapping("/list")
    public ResponseEntity<TableDataInfo> list(SysShopLogin sysShopLogin)
    {
        startPage();
        List<SysShopLogin> list = sysShopLoginService.selectSysShopLoginList(sysShopLogin);
        return new ResponseEntity<>(getDataTable(list),HttpStatus.OK);
    }

    /**
     * 导出商户登录记录列表
     */
    @PreAuthorize("@admin.hasPermi('shop:login:export')")
    @Log(title = "商户登录记录", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public ResponseEntity<Object> export(SysShopLogin sysShopLogin)
    {
        List<SysShopLogin> list = sysShopLoginService.selectSysShopLoginList(sysShopLogin);
        ExcelUtil<SysShopLogin> util = new ExcelUtil<SysShopLogin>(SysShopLogin.class);
        return util.exportExcel(list, "login");
    }

    /**
     * 获取商户登录记录详细信息
     */
    @PreAuthorize("@admin.hasPermi('shop:login:query')")
    @GetMapping(value = "/{infoId}")
    public ResponseEntity<Object> getInfo(@PathVariable("infoId") Long infoId)
    {
        return ResponseEntity.ok(sysShopLoginService.selectSysShopLoginById(infoId));
    }

    /**
     * 新增商户登录记录
     */
    @PreAuthorize("@admin.hasPermi('shop:login:add')")
    @Log(title = "商户登录记录", businessType = BusinessType.INSERT)
    @PostMapping
    public ResponseEntity<Object> add(@RequestBody SysShopLogin sysShopLogin)
    {
        sysShopLoginService.insertSysShopLogin(sysShopLogin);
        return new ResponseEntity<>(HttpStatus.CREATED);
    }

    /**
     * 修改商户登录记录
     */
    @PreAuthorize("@admin.hasPermi('shop:login:edit')")
    @Log(title = "商户登录记录", businessType = BusinessType.UPDATE)
    @PutMapping
    public ResponseEntity<Object> edit(@RequestBody SysShopLogin sysShopLogin)
    {
        sysShopLoginService.updateSysShopLogin(sysShopLogin);
        return new ResponseEntity<>(HttpStatus.NO_CONTENT);
    }

    /**
     * 删除商户登录记录
     */
    @PreAuthorize("@admin.hasPermi('shop:login:remove')")
    @Log(title = "商户登录记录", businessType = BusinessType.DELETE)
	@DeleteMapping("/{infoIds}")
    public ResponseEntity<Object> remove(@PathVariable Long[] infoIds)
    {
        sysShopLoginService.deleteSysShopLoginByIds(infoIds);
        return new ResponseEntity<>(HttpStatus.OK);
    }
}
